//
//  YMVisitorView.swift
//  YMWeiBo
//
//  Created by mimi on 16/7/19.
//  Copyright © 2016年 mimi. All rights reserved.
//

import UIKit
import SnapKit

class YMVisitorView: UIView {

    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //        MARK: - ==========提供公共方法=========
    
    
    func setVisitorView(title:String? ,imgName:String?) {
        
        if let tit = title ,let img = imgName {
            
            circle_iv.hidden = true
            text_lb.text = tit
            house_iv.image = UIImage(named: img)
        }else{
            
            //首页 动画转动
            animationOfHome()
        }
        
        
    }
    
    
   //        MARK: - ========响应事件========
    //点击页面登录和注册按钮
    func didCliclButton() {
        
        closure?()
    }
    
    //转动动画
    func animationOfHome() {
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.toValue = M_PI*2
        anim.duration = 10
        anim.repeatCount = MAXFLOAT
        anim.removedOnCompletion = false
        
        circle_iv.layer.addAnimation(anim, forKey: nil)
    }
    
    func setupUI () {
        
        
        self.backgroundColor = UIColor.init(red: 237/255, green: 237/255, blue: 237/255, alpha: 1)
        
        //        MARK: - 设置控件
        //1.添加控件
        
        addSubview(circle_iv)
        addSubview(hud_iv)
        addSubview(house_iv)
        addSubview(text_lb)
        addSubview(login_bt)
        addSubview(reg_bt)
        
        
        //2.设置约束
        
        circle_iv.snp_makeConstraints { (make) in
            
            make.center.equalTo(self)
            
        }
        
        house_iv.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        hud_iv.snp_makeConstraints { (make) in
            make.center.equalTo(self)
        }
        
        text_lb.snp_makeConstraints { (make) in
            
            make.size.equalTo(CGSize(width: 230, height: 36))
            make.centerX.equalTo(self)
            make.top.equalTo(hud_iv.snp_bottom).offset(16)
        }
        
        login_bt.snp_makeConstraints { (make) in
            
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.leading.equalTo(text_lb)
            make.top.equalTo(text_lb.snp_bottom).offset(16)
            
        }
        
        reg_bt.snp_makeConstraints { (make) in
            
            make.size.equalTo(CGSize(width: 100, height: 36))
            make.trailing.equalTo(text_lb)
            make.top.equalTo(text_lb.snp_bottom).offset(16)
        }
    }

    
    
    
    //        MARK: - ==========  属性声明  =============

    
    
    var closure:(() ->())?
    
    
    
    
    
    //        MARK: -============= 懒加载控件 =============

    //圈圈
   
    lazy var circle_iv:UIImageView = UIImageView(image:UIImage(named: "visitordiscover_feed_image_smallicon") )
    
    //房子
    
    lazy var house_iv:UIImageView = UIImageView(image:UIImage(named: "visitordiscover_feed_image_house") )
    
    //遮照
    lazy var hud_iv:UIImageView = UIImageView(image:UIImage(named: "visitordiscover_feed_mask_smallicon") )
    
    //文字
    lazy var text_lb:UILabel = {
        let lb = UILabel()
        lb.font = UIFont.systemFontOfSize(14)
        lb.textColor = UIColor.grayColor()
        lb.text = "关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜"
        
        lb.numberOfLines = 0
        
        return lb
        
    }()
    //登录
    lazy var login_bt:UIButton = {
       
        let bt = UIButton()
        bt.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        bt.addTarget(self, action: #selector(YMVisitorView.didCliclButton), forControlEvents: .TouchUpInside)
        bt.setTitle("登录", forState: .Normal)
        bt.titleLabel?.font = UIFont.systemFontOfSize(14)
        bt.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: .Normal)
        
        return bt
        
    }()
    
    //注册
    lazy var reg_bt:UIButton = {
        
        let bt = UIButton()
        bt.setTitleColor(UIColor.orangeColor(), forState: .Normal)
        bt.addTarget(self, action: #selector(YMVisitorView.didCliclButton), forControlEvents: .TouchUpInside)
        bt.setTitle("注册", forState: .Normal)
        bt.titleLabel?.font = UIFont.systemFontOfSize(14)
        bt.setBackgroundImage(UIImage(named:"common_button_white_disable"), forState: .Normal)
        
        return bt
        
    }()
    
}
